import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import axios, { AxiosInstance, AxiosRequestConfig, AxiosPromise,AxiosResponse } from 'axios';

// http://apis.imooc.com/api
// axios.defaults.baseURL = '/'
axios.interceptors.request.use( (config: AxiosRequestConfig) => {
    // 添加默认参数
    // config.params = { ...config.params, icode: 'C6A6C4086133360B'}
    // 设置loading true
    store.commit('setLoading', true)
    store.commit('setError', {status: false, message: ''})
    return config
});

axios.interceptors.response.use( config => {
    // 设置loading false
    setTimeout(() => {
        store.commit("setLoading", false)
        store.commit('setError', {status: false, message: ''})
    },2000)
    return config
}, e => {
    console.log("e====",e);
    const error = e.data;
    console.log("error==", error)
    store.commit('setError', {status: true, message: error.message})
    // store.commit("setLoading", false)
    return Promise.reject(error)
})

// axios.get('/api/columns').then(res => {
//     console.log("ajax--res==", res);
// })

createApp(App).use(store).use(router).mount('#app')
